﻿// =====================================================================
// <copyright file="TraceLogTest.cs" author="David R. Guindo">
// 	Copyright (C) 2013. All rights reserved.
// </copyright>
// =====================================================================
// This code is released under the terms of the Apache 2.0 license, 
// http://apache.org/licenses/LICENSE-2.0.html
// =====================================================================

namespace AppBlock.Log.Test
{
    using System;
    using System.Linq;
    using AppBlocks;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    [TestClass]
    public partial class TraceLogTest
    {
        [TestMethod]
        public void Ctor()
        {
            var target = new TraceLog();
            Assert.IsNotNull(target);
            Assert.IsInstanceOfType(target, typeof (ILog));
        }

        [TestMethod]
        public void LogDebug_message_Test()
        {
            const string method = "LogDebug";
            const string str = "test {0}";
            var target = new TraceLog();
            target.LogDebug(str, method);
            Assert.IsTrue(MemoryTraceListener.LogMemory.Contains(string.Format(str, method)));
        }

        [TestMethod]
        public void LogError_message_Test()
        {
            const string method = "LogError";
            const string str = "test {0}";
            var target = new TraceLog();
            target.LogError(str, method);
            Assert.IsTrue(MemoryTraceListener.LogMemory.Contains(string.Format(str, method)));
        }

        [TestMethod]
        public void LogError_exception_Test()
        {
            const string method = "LogError";
            const string str = "test Exception {0}";
            var target = new TraceLog();

            Exception ex = new ArithmeticException("Test Error");
            target.LogError(ex, str, method);
            var text = MemoryTraceListener.LogMemory.FirstOrDefault(s => s.StartsWith(string.Format(str, method)));
            Assert.IsNotNull(text);
            Assert.IsTrue(text.Contains("(ArithmeticException)"));
        }

        [TestMethod]
        public void LogFatal_message_Test()
        {
            const string method = "LogFatal";
            const string str = "test {0}";
            var target = new TraceLog();
            target.LogFatal(str, method);
            Assert.IsTrue(MemoryTraceListener.LogMemory.Contains(string.Format(str, method)));
        }

        [TestMethod]
        public void LogInfo_message_Test()
        {
            const string method = "LogInfo";
            const string str = "test {0}";
            var target = new TraceLog();
            target.LogInfo(str, method);
            Assert.IsTrue(MemoryTraceListener.LogMemory.Contains(string.Format(str, method)));
        }

        [TestMethod]
        public void LogWarning_message_Test()
        {
            const string method = "LogWarning";
            const string str = "test {0}";
            var target = new TraceLog();
            target.LogWarning(str, method);
            Assert.IsTrue(MemoryTraceListener.LogMemory.Contains(string.Format(str, method)));
        }
    }
}